{extend name="common:frm_base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <button name="export" class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-export">导出</button>
                    <button name="export_all" class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-export-all">导出全部</button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
            <script type="text/html" id="iconTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.icon }}>
            </script>
            <script type="text/html" id="sucTpl">
                {{#  if(d.is_suc == 1){ }}
                <span class="layui-btn layui-btn-xs">已发放</span>
                {{#  } else { }}
                <span class="layui-btn layui-btn-xs layui-btn-danger">未发放</span>
                {{#  } }}
            </script>
            <script type="text/html" id="vTpl">
                {{#  if(d.volunteer == 1){ }}
                志愿者
                {{#  } else { }}
                群众
                {{#  } }}
            </script>
            <script type="text/html" id="ssTpl">
                {{#  if(d.s_time > 0){ }}
                已签到
                {{#  } else { }}
                未签到
                {{#  } }}
            </script>
            <script type="text/html" id="eTpl">
                {{#  if(d.e_time > 0){ }}
                已退签
                {{#  } else { }}
                未退签
                {{#  } }}
            </script>
            <script type="text/html" id="sTpl">
                {{#  if(d.status == 1){ }}
                服务中
                {{#  } else if(d.status == 2) { }}
                已完成
                {{#  } else { }}
                待服务
                {{#  } }}
            </script>
            <script type="text/html" id="statusTpl">
                {{#  if(d.status == 1){ }}
                <input type="checkbox" lay-filter="status_change" field="status" table_name="forum"
                       id="{{d.id}}" checked lay-skin="switch" lay-text="开启|关闭">
                {{#  } else { }}
                <input type="checkbox" lay-filter="status_change" field="status" table_name="forum"
                       id="{{d.id}}" lay-skin="switch" lay-text="开启|关闭">
                {{#  } }}
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edits"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                {{#  if(d.is_suc == 0 && d.is_admin==1){ }}
                <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="sends"><i
                        class="layui-icon layui-icon-add-circle"></i>发放</a>
                {{# } }}
            </script>
        </div>
    </div>
</div>

<script>


    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;
        form.on('submit(LAY-user-front-export)', function (data) {
            window.location="/admin/practice/export/id/{$id}/limit/30/page/"+$(".layui-laypage-em").next().html();
        });
        form.on('submit(LAY-user-front-export-all)', function (data) {
            window.location="/admin/practice/export/type/all/id/{$id}";
        });
        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-user-manage', {
                where: field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //用户管理
        table.render({
            elem: '#LAY-user-manage'
            , url: "{:url('Practice/ajaxApply',array('id'=>$id))}" //模拟接口
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'volunteer', title: '报名类型', minWidth: 100,toolbar: '#vTpl'}
                , {field: 'nickname', title: '昵称', minWidth: 100}
                , {field: 'realname', title: '姓名', minWidth: 100}
                , {field: 'sex', title: '性别', minWidth: 100}
                , {field: 'mobile', title: '手机号', minWidth: 100}
                , {field: 'id_card', title: '身份证号', minWidth: 100}
                , {field: 'create_time', title: '报名时间', sort: true,}
                , {field: 's_time', title: '是否签到', minWidth: 100,toolbar: '#ssTpl'}
                , {field: 'e_time', title: '是否退签', minWidth: 100,toolbar: '#eTpl'}
                , {field: 'times', title: '时长', minWidth: 100}
                //, {field: 'send_time', title: '时长', minWidth: 100}
                , {field: 'is_suc', title: '是否完成时长', minWidth: 100,toolbar: '#sucTpl'}
                , {field: 'status', title: '状态', minWidth: 100,toolbar: '#sTpl'}
                , {title: '操作', width:150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}
            ]]
            , method: 'post'
            , page: true
            , limit: 30
            , height: 'full-50'
            , text: '对不起，加载出现异常！'
        });

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            var url = "";
            if (type == 'add') {
                url = "{:url('Forum/add')}";
            }
            active[type] ? active[type].call(this, url, table) : '';
        });
    });
</script>
</body>
</html>
{/block}
